<?php

    // +----------------------------------------------------------------------
    // | order模型
    // +----------------------------------------------------------------------
    // | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 微尘 <yicmf@qq.com>
    // +----------------------------------------------------------------------

    namespace app\model\store;

	use app\model\ucenter\User;
	use yicmf\tools\FlowSn;

    class DepositOrder extends Common
    {

        protected $status_lists = [
            -1 => '已取消',
            0 => '已关闭',
            1 => '未付款',
            2 => '已付款',
            3 => '已发货',
            5 => '已完结'
        ];
        protected $type = [
            'address_info'=>'array'
        ];


        /**
         * 买家
         */
        public function user()
        {
            return $this->belongsTo(User::class);//->field('id,nickname,avatar,phone,introduction,follow,fan,income,store_info,store_address,store_phone,invite_id');
        }


		/**
		 * 写入修改
		 * @param $data
		 */
		public static function onBeforeInsert($data)
		{
			$data['ip'] = request()->ip();
		}

        // 获取器
        public function getOrderStatusAttr($value, $data)
        {
            return isset($this->status_lists[$data['status']]) ? $this->status_lists[$data['status']] : 0;
        }

        public function getAddressInfoTextAttr($value,$data)
        {
            if ($data['send_type'] == 1)
            {
                $info = json_decode($data['address_info'], true);
                return '姓名：'.$info['name'].' 手机号：'.$info['mobile'].' 地址：'.$info['province_name'].$info['city_name'].$info['country_name'].$info['address'].$info['detail_info'];
            }else{
                return  '';
            }
        }
        /**
         * 生成订单号
         * @param $value
         * @return string
         * @author 微尘 <yicmf@qq.com>
         */
        protected function setOrderSnAttr($value)
        {
            return $value ? $value : FlowSn::build(1);
        }
    }
